<?php

/**
 * Enter description here...
 *
 * @author Administrator
 * @package defaultPackage
 * @rcsfile 	$RCSfile: search.php,v $
 * @revision 	$Revision: 1.1 $
 * @date 	$Date: 2009/08/04 04:06:21 $
 */
define('DEDE_FILE','browser');

require_once dirname(__FILE__).'/model/common.inc.php';
require_once DEDEINC.'/datalistcp.class.php';
require_once DEDEASK.'/model/asktype.inc.php';

$tid = empty($tid) ?'' : intval($tid);
$tid2 = empty($tid2) ?'' : intval($tid2);
$multistr ='';
$navtitle = '';

if($tid)
{
	$multistr = $qc = 'tid='.$tid.'&amp;';
	$typesql = "where a.tid=$tid";
	$navtitle = $asktypes[$tid][name];
}
else if ($tid2)
{
	$multistr = $qc = 'tid2='.$tid2.'&amp;';
	$typesql = "where a.tid2=$tid2";
	$navtitle = $asktypes[$tid2][name] .'_'. $asktypes[$asktypes[$tid2][reid]][name];
}
else
{
	$typesql ="where 1=1 ";
}

if (isset($m))
{
	switch($m)
	{
		case 1:
			$multistr .= 'm=1';
			$typesql .=" and a.status>=0 ";
			break;
		case 2:
			$multistr .= 'm=2';
			$typesql .=" and a.status = 0 ";
			break;
		case 3:
			$multistr .= 'm=3';
			$typesql .=" and a.digest=1";
			break;
	}
}

//相关技术

/*
     [id] => 5
                    [name] => 男科炎症
                    [asknum] => 2
                    [reid] => 0
 [tida] => Array
        (
            [id] => 6
            [name] => 妇科疾病
            [asknum] => 0
            [reid] => 0
        )

    [tid2a] => Array
        (
            [id] => 38
            [name] => 白带异常
            [asknum] => 0
            [reid] => 6
        )
*/
foreach($asktypes as $v){

}

$row = $dsql->getone("select count(*) as dd from `#@__ask` as a $typesql");
$askcount = $row['dd'];
$realpages = @ceil($askcount/$tpp);
if($page > $realpages)
{
	$page = $realpages;
}
$page = isset($page) ? max(1, intval($page)) : 1;
$start_limit = ($page - 1) * $tpp;

$multipage = multiy($askcount, $realpages, $tpp, $page, "browser.php?$multistr");

//limit $start_limit, $tpp
$query = "select a.id, a.tid, a.tidname, a.tid2, a.tid2name, a.uid, a.title, a.reward, a.dateline, a.status, a.replies, a.content,m.userid  from #@__ask as a left join  #@__member as m on m.mid=a.uid $typesql order by a.id DESC limit $start_limit, $tpp";
$dsql->Execute('me',$query);
//print_r($asktypes);
while($row = $dsql->getarray())
{
	$row['title'] = cn_substr($row['title'],40);
	$row['title'] = str_replace($q,'<b style="color:red;">'.$q.'</b>',$row['title']);
	$row['content'] = cn_substr($row['content'] ,500);
	$row['tidname'] = $asktypes[$row['tid']]['name'];
	$row['tid2name'] = $asktypes[$row['tid2']]['name'] != ''? $asktypes[$row['tid2']]['name']:$row['tidname'];
	$row['dateline'] = date('Y-m-d',$row['dateline']);
	$asks[] = $row;
}
$tagid = intval($_GET['tid']) ? intval($_GET['tid']) : intval($_GET['tid2']);
$tagid = $asktypes[$tagid];
if($tagid['tagid'])
{

	$query = "select a.title,a.id,ad.redirecturl,a.description from `#@__archives` as a join `#@__addonarticle` as ad on ad.aid = a.id where a.typeid ={$tagid['tagid']} or a.typeid2 ={$tagid['tagid']} limit 3";
	$dsql->Execute('me',$query);
	while($row = $dsql->getarray())
	{
		//$row['title'] = cn_substr($row['title'],40);
		//$row['title'] = str_replace($q,'<b style="color:red;">'.$q.'</b>',$row['title']);
		$samejishu[] = $row;
	}
}
if($m !=3 )
	$template=ASKROOT.'/template/default/browser.htm';
else
	$template=ASKROOT.'/template/default/jingcaihuida.html';
$dtp = new DedeTemplate();
$dtp->LoadTemplate($template);
if($cfg_ask_rewrite=='Y')
{
	$dtp->Display();
	myecho();
	exit();
}
else
{
	$dtp->Display();
}
?>